#pragma once
#include <cassert>

/**
 * A singleton base class
 * Similar to Ogre::Singleton, but this one is not
 * dependent of Ogre.
 * Reference: Game Programming Gems, Scott Bilas.
 */
template <typename T> 
class Singleton
{
protected:
	static T* mInstance;

public:
	Singleton( void )
	{
		assert( !mInstance );
		mInstance = static_cast< T* >( this );
	}

	virtual ~Singleton( void )
	{
		assert( mInstance );
		mInstance = 0;
	}
	/**
	 * @return The single instance by reference
	 */
	static T& instance( void )
	{	
		assert( mInstance );  
		return ( *mInstance ); 
	}

	/**
	 * @return The single instance by pointer
	 */
	static T* instancePtr( void )
	{ 
		return mInstance; 
	}
};

template <typename T> T* Singleton<T>::mInstance = 0;